Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.36 KB

File metadata and controls

35 lines (27 loc) · 1.36 KB

Matrix Exponentiation

Medium

Given an equation of the form f(n) = f(n-1) + f(n-2) where f(0) = 1, F(1) = 1 , the task is to find the nth term of this sequence.
 

Example 1:

Input: n = 3 Output: 3 Explanation: f(3) = f(2) + f(1) = 3 

Example 2:

Input: n = 2 Output: 2 Explanation: f(2) = f(1) + f(0) = 2

 

Yout Task:
You don't need to read or print anything. Your task is to complete the function FindNthTerm() which takes n as input parameter and returns nth term mod 10^9+7 .


Expected Time Compelxity: O(log(n))
Expected Space Complexity: O(K) where K is constant.

 

Constraints:
1 <= n <= 109

close